package com.bleeth.fx.helper;

import cn.hutool.core.util.StrUtil;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.Region;
import javafx.stage.Stage;
import lombok.Builder;

/**
 * @author Sakura
 * @version 1.0
 * @date 2021-11-13 22:48
 * view 注解处理器,同时存储view注解信息,实现跳转
 **/
@Builder
public class DialogHelper {

    private String title;

    private String icon;

    private boolean closeIcon;

    private boolean miniIcon;

    private Stage parentStage;

    @Builder.Default
    private boolean resizable = true;

    @Builder.Default
    private double width = 500D;

    @Builder.Default
    private double height = 300D;

    private Region content;

    public Stage make() {
        Stage dialog = new Stage();
        dialog.setTitle(title);
        dialog.setResizable(resizable);
        if (parentStage != null) {
            dialog.initOwner(parentStage);
        }

        if (StrUtil.isNotEmpty(icon)) {
            dialog.getIcons().add(new Image(this.getClass().getResource(icon).toString()));
        }

        if (content != null) {
            Scene scene = new Scene(content, width, height);
            dialog.setScene(scene);
            content.prefWidthProperty().bind(scene.widthProperty());
            content.prefHeightProperty().bind(scene.heightProperty());
        }
        return dialog;
    }

}
